/*    file: PacketDumper.cpp
 *    desc:
 * 
 * created: 2017-01-04
 *  author: chuanjiang.zh@qq.com
 * company: 
 */

#include "PacketDumper.h"

PacketDumper::PacketDumper()
{
}

PacketDumper::~PacketDumper()
{
	close();
}

bool PacketDumper::open(const char* ip, int port)
{
	comn::SockAddr addr(ip, port);
	m_socket.open(SOCK_STREAM);
	int ret = m_socket.connect(addr);
	return (ret == 0);
}

void PacketDumper::close()
{
	m_socket.close();
}

bool PacketDumper::isOpen()
{
	return m_socket.isOpen();
}

bool PacketDumper::write(const PacketHeader& header)
{
	return write((char*)&header, sizeof(header));
}

bool PacketDumper::write(const char* data, int size)
{
	int length = m_socket.send(data, size);
	return (length == size);
}

bool PacketDumper::write(const uint8_t* data, int size)
{
	int length = m_socket.send((const char*)data, size);
	return (length == size);
}




